import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { NZ_I18N, zh_CN } from 'ng-zorro-antd';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { registerLocaleData } from '@angular/common';
import zh from '@angular/common/locales/zh';

import { LayoutModule } from './layout/layout.module';
import { RoutesModule } from './routes/routes.module';
import { SharedModule } from './shared/shared.module'; /*共享组件*/

// 拦截器
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { ServerInterceptor } from './core/servers/serverInterceptor';

export const httpInterceptorProviders = [
  {
    provide: HTTP_INTERCEPTORS,
    useClass: ServerInterceptor,
    multi: true
  }
];

registerLocaleData(zh);
// ngx-translate 国际化文件
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';

// 加载i18n语言文件
export function I18nHttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http, `assets/i18n/`, '.json');
}

const I18NSERVICE_MODULES = [
  TranslateModule.forRoot({
    loader: {
      provide: TranslateLoader,
      useFactory: I18nHttpLoaderFactory,
      deps: [HttpClient]
    }
  })
];

@NgModule({
  declarations: [
    /*引入当前项目运行的组件*/
    AppComponent
  ],
  imports: [
    /*引入模块依赖组件*/
    LayoutModule,
    RoutesModule,
    SharedModule,
    BrowserModule,
    HttpClientModule,
    BrowserAnimationsModule,
    ...I18NSERVICE_MODULES
  ],
  providers: [
    { provide: NZ_I18N, useValue: zh_CN },
    ...httpInterceptorProviders
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}
